package cn.lger.service;

import cn.lger.dao.ContactDao;
import cn.lger.pojo.Contact;
import cn.lger.pojo.Page;
import cn.lger.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Code that Changed the World
 *
 * @author Pro
 * @date 2018-06-16.
 */
@Service
public class ContactService {

    @Resource
    private ContactDao contactDao;

    @Transactional(rollbackFor = Exception.class)
    public int insertOne(Contact contact){
        return contactDao.insertOne(contact);
    }

    public Page<Contact> findOnePage(Integer currentPage, Integer size) {
        Page<Contact> page = PageUtil.generator(currentPage, size);
        List<Contact> list = contactDao.findOnePage(page.getPage(), page.getSize());
        page.setContent(list);
        page.setCount(contactDao.getTotal());
        return page;
    }

    @Transactional(rollbackFor = Exception.class)
    public int deleteOneById(int id) {
        return contactDao.deleteOneById(id);
    }
}
